<template>
	<view class="center">
		<view class="logo" @click="goLogin" :hover-class="!login ? 'logo-hover' : ''">
			<image class="logo-img" :src="login ? userInfo.avatarUrl :avatarUrl"></image>
			<!-- <image class="logo-img" src="https://wx-xinpeng-upload.oss-cn-hangzhou.aliyuncs.com/20180903/1535944424773.jpg"></image> -->
			<view class="logo-title">
				<text class="uer-name">Hi，{{login ? userInfo.username : '您未登录'}}</text>
				<!-- <text class="uer-name">Hi，15050835601</text> -->
				<text class="go-login navigat-arrow" v-if="!login">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item" data-page="business" @click="goPage">
				<text class="list-icon">&#xe60f;</text>
				<text class="list-text">业务管理</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item border-bottom" data-page="help" @click="goPage">
				<text class="list-icon">&#xe60b;</text>
				<text class="list-text">帮助与反馈</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item" data-page="secret" @click="goPage">
				<text class="list-icon">&#xe65f;</text>
				<text class="list-text">服务条款及隐私</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item" data-page="about" @click="goPage">
				<text class="list-icon">&#xe614;</text>
				<text class="list-text">关于应用</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item" data-page="setting" @click="goPage">
				<text class="list-icon">&#xe614;</text>
				<text class="list-text">设置</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
	</view>
</template>

<script>
	import { userinfo } from '@/api/user.js'
	//import '@/mock/user.js'
	
	export default {
		data() {
			return {
				login: false,
				avatarUrl: "../../static/uni-center/logo.png",
				userInfo: {}
			}
		},
		onLoad() {
			//this.getUserInfo()
		},
		methods: {
			goLogin() {
				if (!this.login) {
					uni.navigateTo({
						url: '../login/login?redirect=' + this.$mp.page.route
					})
				}
			},
			
			getUserInfo(){
				userinfo().then(res => {
					if(res.statusCode === 1) {
						this.login = true
						this.userInfo = res.result
					}
				}).catch(err => {
					console.log(err)
				})
			},
			
			goPage(e) {
				let page = e.currentTarget.dataset.page
				if(page === 'business') uni.switchTab({url:"../business/list"})
				if(page === 'secret') uni.navigateTo({url:"./secret/secret"})
				if(page === 'about') uni.navigateTo({url:"./about/about"})
				if(page === 'help') uni.navigateTo({url:"./help/help"})
			}
		}
	}
</script>

<style>
	@font-face {
		font-family: texticons;
		font-weight: normal;
		font-style: normal;
		src: url('https://at.alicdn.com/t/font_984210_5cs13ndgqsn.ttf') format('truetype');
	}

	page,
	view {
		display: flex;
	}

	page {
		background-color: #f8f8f8;
	}

	.center {
		flex-direction: column;
	}

	.logo {
		width: 750upx;
		height: 240upx;
		padding: 20upx 20upx 20upx 40upx;
		box-sizing: border-box;
		background:url(../../static/bg_user.jpg)no-repeat center;
		background-size: cover;
		flex-direction: row;
		align-items: center;
	}

	.logo-hover {
		opacity: 0.8;
	}

	.logo-img {
		width: 150upx;
		height: 150upx;
		border-radius: 150upx;
	}

	.logo-title {
		height: 150upx;
		flex: 1;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
		margin-left: 40upx;
		font-weight: 700;
	}

	.uer-name {
		height: 60upx;
		line-height: 60upx;
		font-size: 38upx;
		color: #FFFFFF;
	}

	.go-login.navigat-arrow {
		font-size: 38upx;
		color: #FFFFFF;
	}

	.login-title {
		height: 150upx;
		align-items: self-start;
		justify-content: center;
		flex-direction: column;
		margin-left: 20upx;
	}

	.center-list {
		background-color: #FFFFFF;
		margin-top: 20upx;
		width: 750upx;
		flex-direction: column;
	}

	.center-list-item {
		height: 100upx;
		width: 750upx;
		box-sizing: border-box;
		flex-direction: row;
		padding: 0upx 20upx;
		align-items: center;
	}

	.border-bottom {
		border-bottom-width: 1upx;
		border-color: #ebebeb;
		border-bottom-style: solid;
	}

	.list-icon {
		width: 40upx;
		height: 90upx;
		line-height: 90upx;
		font-size: 34upx;
		color: #0089ff;
		text-align: center;
		font-family: texticons;
		margin-right: 20upx;
	}

	.list-text {
		height: 90upx;
		line-height: 90upx;
		font-size: 34upx;
		color: #555;
		flex: 1;
		text-align: left;
	}

	.navigat-arrow {
		height: 90upx;
		width: 40upx;
		line-height: 90upx;
		font-size: 34upx;
		color: #555;
		text-align: right;
		font-family: texticons;
	}
</style>